home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-03 | 776 b | 33 lines | [TEXT/MPS ] |
- c Dynary.txt is an example of dynamically allocating
- c an array in FORTRAN:
-
- c Example provided for owners of Language Systems FORTRAN
- c © 1992 Language Systems Corp.
- !!MP inlines.f
-
- program dynarray
-
- pointer /real*4/ myptr !put the appropriate data type for the array in the //'s
- integer*4 memneeded, numelems
-
- Write(*,*) 'How many elements in array?'
- Read(*,*) numelems !could also be calculated
- memneeded = numelems*4 !number of elements times size of each element in bytes
- myptr = NewPtr(memneeded)
- if (myptr .ne. 0) then
- call sub1(%val(myptr),numelems) !%val is the "trick" that makes this work
- end if
- end
-
-
- subroutine Sub1(a,i) !This is just normal FORTRAN
- Integer*4 i,j
- Real*4 a(i)
-
- do j = 1,i
- a(j) = j*1.532
- end do
- write(*,*) a
- return
- end
-